﻿// 对接积分模块
#include "pch.h"

extern DYNLIB_HANDLE hAnalysis;

CAnalysis::CAnalysis() {}

#define DEFINE_ANALYSIS_API(RETURN_TYPE, NAME, ...) \
    typedef RETURN_TYPE (*MYFUNCTION)(__VA_ARGS__); \
    RETURN_TYPE bRet = (RETURN_TYPE)(0);

#define CALL_ANALYSIS_API(NAME, ...)                                                            \
    if (hAnalysis != NULL)                                                                      \
    {                                                                                           \
        MYFUNCTION NAME##_ = (MYFUNCTION)DYNLIB_GETSYM(hAnalysis, #NAME);                       \
        if (NAME##_ != NULL)                                                                    \
        {                                                                                       \
            bRet = NAME##_(__VA_ARGS__);                                                        \
        }                                                                                       \
        else                                                                                    \
        {                                                                                       \
            STD_CERR << "Error loading symbol " << #NAME << ": " << DYNLIB_ERROR() << STD_ENDL; \
        }                                                                                       \
    }                                                                                           \
    return bRet;

typedef void (*DRAWTICKMARK)(int32_t, int32_t, TICKMARK);

BOOL CAnalysis::InitAnalPool(int32_t maxChannels, int32_t realChannels, void (*drawTickMark)(int32_t ch, int32_t time, TICKMARK tickmark))
{
    DEFINE_ANALYSIS_API(BOOL, InitAnalPool, int32_t, int32_t, DRAWTICKMARK);
    CALL_ANALYSIS_API(InitAnalPool, maxChannels, realChannels, drawTickMark);
}

BOOL CAnalysis::ExitAnalPool()
{
    DEFINE_ANALYSIS_API(BOOL, ExitAnalPool);
    CALL_ANALYSIS_API(ExitAnalPool);
}

int32_t CAnalysis::GetAnalPoolVolume(int32_t *maxReal, int32_t *maxRedo)
{
    DEFINE_ANALYSIS_API(int32_t, GetAnalPoolVolume, int32_t *, int32_t *);
    CALL_ANALYSIS_API(GetAnalPoolVolume, maxReal, maxRedo);
}

BOOL CAnalysis::OpenAnal(int32_t ch, TSMPBAG *smpBag, TDLLIPINF *ipInf, TDLLEPINF *epInf, TDLLIDTINF *idtInf, TDLLRESINF *resInf, TDLLSTDINF *stdInf)
{
    typedef BOOL (*MYFUNCTION)(int32_t, TSMPBAG *, TDLLIPINF *, TDLLEPINF *, TDLLIDTINF *, TDLLRESINF *, TDLLSTDINF *);
    BOOL bRet = (BOOL)(0);
    ;
    if (hAnalysis != 0)
    {
        MYFUNCTION OpenAnal_ = (MYFUNCTION)DYNLIB_GETSYM(hAnalysis, "OpenAnal");
        if (OpenAnal_ != 0)
        {
            bRet = OpenAnal_(ch, smpBag, ipInf, epInf, idtInf, resInf, stdInf);
        }
    }
    return bRet;
    ;
}

BOOL CAnalysis::CloseAnal(int32_t ch)
{
    DEFINE_ANALYSIS_API(BOOL, CloseAnal, int32_t);
    CALL_ANALYSIS_API(CloseAnal, ch);
}

BOOL CAnalysis::StartAnal(int32_t ch)
{
    DEFINE_ANALYSIS_API(BOOL, StartAnal, int32_t);
    CALL_ANALYSIS_API(StartAnal, ch);
}

BOOL CAnalysis::StopAnal(int32_t ch)
{
    DEFINE_ANALYSIS_API(BOOL, StopAnal, int32_t);
    CALL_ANALYSIS_API(StopAnal, ch);
}

CODE CAnalysis::ExecAnal(int32_t ch)
{
    DEFINE_ANALYSIS_API(CODE, ExecAnal, int32_t);
    CALL_ANALYSIS_API(ExecAnal, ch);
}

int32_t CAnalysis::GetAnalTime(int32_t ch)
{
    DEFINE_ANALYSIS_API(int32_t, GetAnalTime, int32_t);
    CALL_ANALYSIS_API(GetAnalTime, ch);
}

char *CAnalysis::GetErrMsg(int32_t ch)
{
    DEFINE_ANALYSIS_API(char *, GetErrMsg, int32_t);
    CALL_ANALYSIS_API(GetErrMsg, ch);
}

BOOL CAnalysis::TickAnal(int32_t ch)
{
    DEFINE_ANALYSIS_API(BOOL, TickAnal, int32_t);
    CALL_ANALYSIS_API(TickAnal, ch);
}

BOOL CAnalysis::AnalOpened(int32_t ch)
{
    DEFINE_ANALYSIS_API(BOOL, AnalOpened, int32_t);
    CALL_ANALYSIS_API(AnalOpened, ch);
}

BOOL CAnalysis::AnalBusy(int32_t ch)
{
    DEFINE_ANALYSIS_API(BOOL, AnalBusy, int32_t);
    CALL_ANALYSIS_API(AnalBusy, ch);
}

int32_t CAnalysis::GetAnalOpened(int32_t **chArray)
{
    DEFINE_ANALYSIS_API(int32_t, GetAnalOpened, int32_t **);
    CALL_ANALYSIS_API(GetAnalOpened, chArray);
}

int32_t CAnalysis::GetAnalBusy(int32_t **chArray)
{
    DEFINE_ANALYSIS_API(int32_t, GetAnalBusy, int32_t **);
    CALL_ANALYSIS_API(GetAnalBusy, chArray);
}

BOOL CAnalysis::SetUkPkFactor(int32_t ch, TUkPkFactor *lpUkPkFactor)
{
    DEFINE_ANALYSIS_API(BOOL, SetUkPkFactor, int32_t, TUkPkFactor *);
    CALL_ANALYSIS_API(SetUkPkFactor, ch, lpUkPkFactor);
}

BOOL CAnalysis::SetIdtTimeOfs(int32_t ch, float fTimeOfs)
{
    DEFINE_ANALYSIS_API(BOOL, SetIdtTimeOfs, int32_t, float);
    CALL_ANALYSIS_API(SetIdtTimeOfs, ch, fTimeOfs);
}

BOOL CAnalysis::SetYMinUnit(int32_t ch, double yMinUnit)
{
    DEFINE_ANALYSIS_API(BOOL, SetYMinUnit, int32_t, double);
    CALL_ANALYSIS_API(SetYMinUnit, ch, yMinUnit);
}

BOOL CAnalysis::SetIdtQualitMode(int32_t ch, int32_t nQualitMode, float fTimeWindow)
{
    DEFINE_ANALYSIS_API(BOOL, SetIdtQualitMode, int32_t, int32_t, float);
    CALL_ANALYSIS_API(SetIdtQualitMode, ch, nQualitMode, fTimeWindow);
}

BOOL CAnalysis::SetXMinUnitK(int32_t ch, double xMinUnitK)
{
    DEFINE_ANALYSIS_API(BOOL, SetXMinUnitK, int32_t, double);
    CALL_ANALYSIS_API(SetXMinUnitK, ch, xMinUnitK);
}

BOOL CAnalysis::SetMiscellaneous(int32_t ch, uint64_t wParam, uint64_t lParam)
{
#if defined(_WIN64) || defined(__LP64__) || defined(__x86_64__)
    DEFINE_ANALYSIS_API(BOOL, SetMiscellaneous, int32_t, uint64_t, uint64_t);
    CALL_ANALYSIS_API(SetMiscellaneous, ch, wParam, lParam);
#else
    DEFINE_ANALYSIS_API(BOOL, SetMiscellaneous, int32_t, DWORD, DWORD);
    CALL_ANALYSIS_API(SetMiscellaneous, ch, (DWORD)wParam, (DWORD)lParam);
#endif
}

BOOL CAnalysis::EvalResult(TDLLRESINF *resInf, TDLLEPINF *epInf, TDLLIDTINF *idtInf, TDLLMETRIC *metric)
{
    DEFINE_ANALYSIS_API(BOOL, EvalResult, TDLLRESINF *, TDLLEPINF *, TDLLIDTINF *, TDLLMETRIC *);
    CALL_ANALYSIS_API(EvalResult, resInf, epInf, idtInf, metric);
}

BOOL CAnalysis::EvalColumnPerf(TDLLResultListItem *pHead, int32_t pCount, int32_t *smpHead, float freq)
{
    DEFINE_ANALYSIS_API(BOOL, EvalColumnPerf, TDLLResultListItem *, int32_t, int32_t *, float);
    CALL_ANALYSIS_API(EvalColumnPerf, pHead, pCount, smpHead, freq);
}

double CAnalysis::EvalKHeightW(TDLLResultListItem *pHead, int32_t *smpHead, double k, float freq, double *lpWL, double *lpWR)
{
    DEFINE_ANALYSIS_API(double, EvalKHeightW, TDLLResultListItem *, int32_t *, double, float, double *, double *);
    CALL_ANALYSIS_API(EvalKHeightW, pHead, smpHead, k, freq, lpWL, lpWR);
}

BOOL CAnalysis::EvalColumnPerfEx(TDLLResultListItem *pHead, int32_t pCount, int32_t *smpHead, float freq, double xMinUnitK)
{
    DEFINE_ANALYSIS_API(BOOL, EvalColumnPerfEx, TDLLResultListItem *, int32_t, int32_t *, float, double);
    CALL_ANALYSIS_API(EvalColumnPerfEx, pHead, pCount, smpHead, freq, xMinUnitK);
}

double CAnalysis::EvalKHeightWEx(TDLLResultListItem *pHead, int32_t *smpHead, double k, float freq, double xMinUnitK, double *lpWL, double *lpWR)
{
    DEFINE_ANALYSIS_API(double, EvalKHeightWEx, TDLLResultListItem *, int32_t *, double, float, double, double *, double *);
    CALL_ANALYSIS_API(EvalKHeightWEx, pHead, smpHead, k, freq, xMinUnitK, lpWL, lpWR);
}

BOOL CAnalysis::EvalGroup(TDLLGRPINF *grpInf, TDLLRESINF *resInf)
{
    DEFINE_ANALYSIS_API(BOOL, EvalGroup, TDLLGRPINF *, TDLLRESINF *);
    CALL_ANALYSIS_API(EvalGroup, grpInf, resInf);
}

BOOL CAnalysis::EvalCalibFact(TDLLSTDINF *stdInf, TEPara *epara, TDLLIDTINF *idtInf)
{
    DEFINE_ANALYSIS_API(BOOL, EvalCalibFact, TDLLSTDINF *, TEPara *, TDLLIDTINF *);
    CALL_ANALYSIS_API(EvalCalibFact, stdInf, epara, idtInf);
}

BOOL CAnalysis::ManualPeakStart(int32_t ch, float startTime)
{
    DEFINE_ANALYSIS_API(BOOL, ManualPeakStart, int32_t, float);
    CALL_ANALYSIS_API(ManualPeakStart, ch, startTime);
}

BOOL CAnalysis::ManualPeakEnd(int32_t ch, float endTime)
{
    DEFINE_ANALYSIS_API(BOOL, ManualPeakEnd, int32_t, float);
    CALL_ANALYSIS_API(ManualPeakEnd, ch, endTime);
}

BOOL CAnalysis::ManualPeakMoveSplit(int32_t ch, float valleyTime)
{
    DEFINE_ANALYSIS_API(BOOL, ManualPeakMoveSplit, int32_t, float);
    CALL_ANALYSIS_API(ManualPeakMoveSplit, ch, valleyTime);
}

BOOL CAnalysis::ManualPeakAddSplit(int32_t ch, float splitTime)
{
    DEFINE_ANALYSIS_API(BOOL, ManualPeakAddSplit, int32_t, float);
    CALL_ANALYSIS_API(ManualPeakAddSplit, ch, splitTime);
}

BOOL CAnalysis::ManualPeakDelSplit(int32_t ch, float splitTime)
{
    DEFINE_ANALYSIS_API(BOOL, ManualPeakDelSplit, int32_t, float);
    CALL_ANALYSIS_API(ManualPeakDelSplit, ch, splitTime);
}

BOOL CAnalysis::ManualPeakAddOnlyOne(int32_t ch, float beginTime, float endTime)
{
    DEFINE_ANALYSIS_API(BOOL, ManualPeakAddOnlyOne, int32_t, float, float);
    CALL_ANALYSIS_API(ManualPeakAddOnlyOne, ch, beginTime, endTime);
}

BOOL CAnalysis::ManualPeakDelete(int32_t ch, float beginTime, float endTime)
{
    DEFINE_ANALYSIS_API(BOOL, ManualPeakDelete, int32_t, float, float);
    CALL_ANALYSIS_API(ManualPeakDelete, ch, beginTime, endTime);
}

BOOL CAnalysis::ManualBaseValley(int32_t ch, float beginTime, float endTime)
{
    DEFINE_ANALYSIS_API(BOOL, ManualBaseValley, int32_t, float, float);
    CALL_ANALYSIS_API(ManualBaseValley, ch, beginTime, endTime);
}

BOOL CAnalysis::ManualBaseTogether(int32_t ch, float beginTime, float endTime)
{
    DEFINE_ANALYSIS_API(BOOL, ManualBaseTogether, int32_t, float, float);
    CALL_ANALYSIS_API(ManualBaseTogether, ch, beginTime, endTime);
}

BOOL CAnalysis::ManualBaseTailTangent(int32_t ch, float beginTime, float endTime)
{
    DEFINE_ANALYSIS_API(BOOL, ManualBaseTailTangent, int32_t, float, float);
    CALL_ANALYSIS_API(ManualBaseTailTangent, ch, beginTime, endTime);
}

BOOL CAnalysis::ManualBaseFrontTangent(int32_t ch, float beginTime, float endTime)
{
    DEFINE_ANALYSIS_API(BOOL, ManualBaseFrontTangent, int32_t, float, float);
    CALL_ANALYSIS_API(ManualBaseFrontTangent, ch, beginTime, endTime);
}

BOOL CAnalysis::ManualBaseForwHori(int32_t ch, float beginTime, float endTime)
{
    DEFINE_ANALYSIS_API(BOOL, ManualBaseForwHori, int32_t, float, float);
    CALL_ANALYSIS_API(ManualBaseForwHori, ch, beginTime, endTime);
}

BOOL CAnalysis::ManualBaseBackHori(int32_t ch, float beginTime, float endTime)
{
    DEFINE_ANALYSIS_API(BOOL, ManualBaseBackHori, int32_t, float, float);
    CALL_ANALYSIS_API(ManualBaseBackHori, ch, beginTime, endTime);
}

BOOL CAnalysis::ManualParaWidth(int32_t ch, float beginTime, float endTime, float pkWidth)
{
    DEFINE_ANALYSIS_API(BOOL, ManualParaWidth, int32_t, float, float, float);
    CALL_ANALYSIS_API(ManualParaWidth, ch, beginTime, endTime, pkWidth);
}

BOOL CAnalysis::ManualParaNoise(int32_t ch, float beginTime, float endTime, float pkNoise)
{
    DEFINE_ANALYSIS_API(BOOL, ManualParaNoise, int32_t, float, float, float);
    CALL_ANALYSIS_API(ManualParaNoise, ch, beginTime, endTime, pkNoise);
}

BOOL CAnalysis::UpdateResult(int32_t ch, int32_t pStart, int32_t pEnd)
{
    DEFINE_ANALYSIS_API(BOOL, UpdateResult, int32_t, int32_t, int32_t);
    CALL_ANALYSIS_API(UpdateResult, ch, pStart, pEnd);
}

double CAnalysis::CvtConcToAmt(double conc, TDLLMETRIC *metric, int32_t method)
{
    DEFINE_ANALYSIS_API(double, CvtConcToAmt, double, TDLLMETRIC *, int32_t);
    CALL_ANALYSIS_API(CvtConcToAmt, conc, metric, method);
}

double CAnalysis::CvtConcToAmtByIstd(double conc, TDLLMETRIC *metric)
{
    DEFINE_ANALYSIS_API(double, CvtConcToAmtByIstd, double, TDLLMETRIC *);
    CALL_ANALYSIS_API(CvtConcToAmtByIstd, conc, metric);
}

BOOL CAnalysis::LearnAutoPara(AUTOPOOL *autoPool, float freq, AUTOPARA *autoPara)
{
    DEFINE_ANALYSIS_API(BOOL, LearnAutoPara, AUTOPOOL *, float, AUTOPARA *);
    CALL_ANALYSIS_API(LearnAutoPara, autoPool, freq, autoPara);
}

BOOL CAnalysis::MakeAutoPara(int32_t *buf, int32_t len, float freq, AUTOPARA *autoPara)
{
    DEFINE_ANALYSIS_API(BOOL, MakeAutoPara, int32_t *, int32_t, float, AUTOPARA *);
    CALL_ANALYSIS_API(MakeAutoPara, buf, len, freq, autoPara);
}

BOOL CAnalysis::LearnAutoIPara(AUTOPOOL *autoPool, float freq, AUTOIPARA *autoIPara)
{
    DEFINE_ANALYSIS_API(BOOL, LearnAutoIPara, AUTOPOOL *, float, AUTOIPARA *);
    CALL_ANALYSIS_API(LearnAutoIPara, autoPool, freq, autoIPara);
}

BOOL CAnalysis::MakeAutoIPara(int32_t *buf, int32_t len, float freq, AUTOIPARA *autoIPara)
{
    DEFINE_ANALYSIS_API(BOOL, MakeAutoIPara, int32_t *, int32_t, float, AUTOIPARA *);
    CALL_ANALYSIS_API(MakeAutoIPara, buf, len, freq, autoIPara);
}

BOOL CAnalysis::MdyAnalStopTime(int32_t ch, float fMinutes)
{
    DEFINE_ANALYSIS_API(BOOL, MdyAnalStopTime, int32_t, float);
    CALL_ANALYSIS_API(MdyAnalStopTime, ch, fMinutes);
}

BOOL CAnalysis::MdyPeakSmpHead(int32_t ch, int32_t *pSmpHead)
{
    DEFINE_ANALYSIS_API(BOOL, MdyPeakSmpHead, int32_t, int32_t *);
    CALL_ANALYSIS_API(MdyPeakSmpHead, ch, pSmpHead);
}

TDLLIDTListItem &TDLLIDTListItem::operator=(const TCompList &src)
{
    *this = TDLLIDTListItem();
    this->f0 = src.f0;
    this->f1 = src.f1;
    this->f2 = src.f2;
    this->f3 = src.f3;
    this->k = src.k;
    this->k1 = src.k1;
    this->cLower = src.cLower;
    this->cUpper = src.cUpper;
    this->r = src.r;
    this->basedOn = src.basedOn;
    this->weight = src.weight;
    this->Time = src.Time;
    this->band = src.band;
    this->istdNoSelf = src.istdNoSelf;
    this->TypeEx = src.TypeEx;
    this->istdNoUsed = src.istdNoUsed;
    BYTE_COPY(src.Name, Name, sizeof(Name));
    return *this;
}

TDLLResultListItem &TDLLResultListItem::operator=(const TAnalResult &src)
{
    *this = TDLLResultListItem();
    this->Area = src.Area;
    this->AreaPer = src.AreaPer;
    this->Conc = src.Conc;
    this->Areas = src.Areas;
    this->Arear = src.Arear;
    this->Areae = src.Areae;
    this->ALeft = src.ALeft;
    this->ARight = src.ARight;
    this->Idno = src.Idno;
    this->RTime = src.RTime;
    this->Height = src.Height;
    this->W50 = src.W50;
    this->Sigma5 = src.Sigma5;
    this->Plates = src.Plates;
    this->Resolution = src.Resolution;
    this->Symmetry = src.Symmetry;
    this->M1 = src.M1;
    this->M2 = src.M2;
    this->fts = src.fts;
    this->fte = src.fte;
    this->ts = src.ts;
    this->tr = src.tr;
    this->te = src.te;
    this->hs = src.hs;
    this->hsv = src.hsv;
    this->hr = src.hr;
    this->he = src.he;
    this->hev = src.hev;
    BYTE_COPY(src.TypeCode, TypeCode, sizeof(TypeCode));
    BYTE_COPY(src.Name, Name, sizeof(Name));
    BYTE_COPY(src.ReserveX, ReserveX, sizeof(ReserveX));
    return *this;
}